package com.shawn.baseappbygroovydsl.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.shawn.baseappbygroovydsl.R
import eee.drama.idea_chat.bean.BeanRedGroup

import eee.drama.idea_chat.databinding.ItemChatGroupBinding
import kotlin.properties.Delegates


class ChatListAdapter() : BaseQuickAdapter<BeanRedGroup, ChatListAdapter.VH>() {

    class VH(view: View) : RecyclerView.ViewHolder(view)

    var message by Delegates.observable(0, onChange = { _, old, new ->
        if (old != new) {
            notifyDataSetChanged()
        }
    })

    override fun onBindViewHolder(holder: VH, position: Int, item: BeanRedGroup?) {
        item?.let { _bean ->
            val bind = ItemChatGroupBinding.bind(holder.itemView)
            bind.sivIcon.setImageResource(item.icon)
            bind.sivDot.visibility = if (item.isShowDot) {
                View.VISIBLE
            } else {
                View.GONE
            }
            bind.tvTitle.text = item.title
            bind.tvSubTitle1.text = item.subTitle1
            bind.tvSubTitle2.text = item.subTitle2
            bind.tvNum.text = item.msgCount
        }
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        val view =
            LayoutInflater.from(parent.context).inflate(eee.drama.idea_chat.R.layout.item_chat_group, parent, false)
        return VH(view)
    }
}